export default function ajax(url = '', params = {}, type = 'GET') {
  // 定义promise对象
  let promise = new Promise((resolve, reject) => {
      params.user_token = wx.getStorageSync('userToken')
    wx.request({
      url: url,
      data: params,
      method: type,
      header: {
        "content-type": "application/json"
      },
      success: res => {
        if(res.data.level == "success"){
          resolve(res)
        }else {
          if(res.data.data == "no_login"){
            wx.showToast({
            	icon:'none',
				title:res.data.message,
				duration: 1500
            })
			setTimeout(()=>{
				wx.switchTab({
				    url:"/pages/person/person"
				  });
			},1500)
          }else {
            resolve(res)
          }
        }
      },
      fail: err => {
        reject(err)
      }
    })
  })
  return promise
}
